package com.mallcai.bigdata.ladon.dpl.entity.system;

import com.mallcai.bigdata.ladon.dpl.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author gst
 * @date 2019-12-30 20:36
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class User extends BaseEntity {
    /**
     * 密码
     */
    private transient String password;
    /**
     * 昵称
     */
    private String       nickname;
    /**
     * 用户名
     */
    private String       username;
    /**
     * 邮件激活码
     */
    private String       emailActiveCode;
    /**
     * 部门编号
     */
    private String       department;
    /**
     * 部门名称
     */
    private String       departmentName;
    /**
     * 职位
     */
    private String       position;
    /**
     * 状态 0 - 注册未激活; 1 - 正常; 2 - 锁定(不可用)
     */
    private Integer      status;
    /**
     * 头像
     */
    private String       avatar;
    /**
     * 手机号
     */
    private String       phone;
    /**
     * 个性签名
     */
    private String       signature;
    /**
     * 邮箱号
     */
    private String       email;
    /**
     * 地址
     */
    private String       address;
    /**
     * 个人标签
     */
    private List<String> tags;

    /**
     * 扩展信息
     */

    private String       roleNameStr;
    private List<String> roleNames;
    private String       roleIdStr;
    private List<Long>   roleIds;

    public User(String username, String nickname, String password) {
        this.username = username;
        this.nickname = nickname;
        this.password = password;
    }

    public void setRoleNameStr(String val) {
        this.roleNameStr = val;
        if (StringUtils.isNotBlank(val)) {
            String[] tmps = StringUtils.split(val, ",");
            this.roleNames = Arrays.asList(tmps);
        }
    }

    public void setRoleIdStr(String val) {
        this.roleIdStr = val;
        if (StringUtils.isNotBlank(val)) {
            String[] tmps = StringUtils.split(val, ",");
            List<Long> ids = new ArrayList<>();
            for (String tmp : tmps) {
                ids.add(Long.valueOf(tmp));
            }
            this.roleIds = ids;
        }
    }
}
